<template>
	<view >
		<view class="news-item" v-for="item in news" :key="item.id" @click="goDetail(item.id)">
			<image :src="item.img_url" class="image"></image>
			<view class="right">
				
				<view class="title">
					{{item.title}}
				</view>
				
				<view class="info">
					<text>发表时间: {{item.public_time | formatDate}}</text>
					<text>浏览次数: {{item.click}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"NewsItem",
		props: {
			news: {
				type: Array,
				default() {
					return []
				}
			}
		},
		filters: {
			formatDate(date) {
				const newDate = new Date(date)
				// console.log(newDate)
				const year = newDate.getFullYear()
				const month = (newDate.getMonth() + 1).toString().padStart(2,0)
				const day = newDate.getDate().toString().padStart(2,0)
				return year + '-' + month + '-' + day
			}
		},
		methods: {
			goDetail(index) {
				this.$emit('goDetail', index)
			}
		}
	}
</script>

<style lang="scss">
	.news-item {
		display: flex;
		padding: 10rpx 20rpx;
		border-bottom: 1px solid $shop-color;
		.image {
			min-width: 200rpx;
			max-width: 200rpx;
			height: 150rpx;	
		}
		.right {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			margin-left: 15rpx;
			.title {
				font-size: 33rpx;
			}
			.info {
				font-size: 24rpx;
				text:nth-child(2) {
					margin-left: 30rpx;
				}
			}
		}
	}

</style>
